package 分治.easy;

/**
 * @author Lw中
 * @date 2021/9/6 22:34
 */
public class QiLingSi {

    // 704.二分查找
    public int search(int[] nums, int target) {
        int i = 0, j = nums.length - 1;
        while (i <= j) {
            int m = (i + j) / 2;
            if (nums[m] < target) i = m + 1;
            else if (nums[m] > target) j = m - 1;
            else return m;
        }
        return -1;
    }

}
